<template>
  <div class="home">
    <el-container>
      <el-aside width="200px">
        <router-link to="/" class="logo">
          <img src="../assets/logo.png" alt="" />
        </router-link>

        <!--el-submenu的index属性应该是唯一不重复的 -->
        <!--  default-active 默认选中项 -->
        <!--  router 把index当成vue-router里的to属性使用 作为path进行路由跳转-->
        <!--    unique-opened 是否打开一个子菜单 -->
        <el-menu
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="#333"
          text-color="#fff"
          active-text-color="#ffd04b"
          unique-opened
          router
        >
          <el-menu-item index="/">首页</el-menu-item>
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>文章管理</span>
            </template>
            <el-menu-item index="/home/post_list">文章列表</el-menu-item>
            <el-menu-item index="/home/post_publish">发布文章</el-menu-item>
          </el-submenu>

          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>栏目管理</span>
            </template>
            <el-menu-item index="2-1">栏目列表</el-menu-item>
            <!-- <el-menu-item index="2-2">其他菜单</el-menu-item> -->
          </el-submenu>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header height="80px">
          <img class="avatar" :src="userInfo.head_img | imgUrl" />
          <span class="nickname">欢迎你:{{ userInfo.nickname }}</span>
          <el-button type="danger">退出</el-button>
        </el-header>
        <el-main>
          <!-- 路由挂载点 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { userDetailsAPI } from "../apis/user";
import { getUserId } from "../utils/locaData";
export default {
  data() {
    return {
      userInfo: {},
    };
  },
  async created() {
    const id = getUserId();
    console.log(id);
    const res = await userDetailsAPI(id);
    // console.log(res);
    this.userInfo = res.data.data;
  },
};
</script>

<style lang="less" scoped>
.el-container {
  height: 100vh;
}
.el-header {
  background-color: #333;
  color: #fff;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  .avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }
  .nickname {
    margin: 0 10px;
  }
}

.el-aside {
  background-color: #000;
  color: #fff;
  .logo {
    width: 100%;
    background-color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 80px;
  }
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}
</style>